package com.lottery.game.runner.v2.common;

import org.springframework.web.socket.WebSocketSession;

import java.util.Map;
import java.util.Vector;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class WebSocketContextHolder {

	private static Lock lock = new ReentrantLock();

	private static final Map<String, WebSocketSession> CONTEXT_HOLDER = new ConcurrentHashMap<>();

	public static Vector<String> keys = new Vector<>();

	public static void put(String key, WebSocketSession session) {
		lock.lock();
		try {
			CONTEXT_HOLDER.put(key, session);
		} catch (Exception e) {
			 log.error("Put WebSocketSession into context, error: {}", e.getMessage());
		} finally {
			lock.unlock();
		}
	}

	public static WebSocketSession get(String key) {
		return CONTEXT_HOLDER.get(key);
	}

}
